<template>
	<a-card :bordered="false">
		<div class="table-page-search-wrapper">
			<a-form layout="inline">
				<a-row :gutter="48">

					<a-col :md="8" :sm="24">
						<a-form-item label="生产单号">
							<a-input v-model="queryParam.orderNumber" placeholder="请输入生产单号" />
						</a-form-item>
					</a-col>

					<a-col :md="24" :sm="24" v-if="!isFour()">
						<a-form-item label="归属公司：">
							<FCOrgRadioGroup v-model="queryParam.orgId" :filter-types="[$businessEnum.ORG_TYPE_ENUM.COMPANY.id]" />
							<!--              <a-radio-group default-value="" button-style="solid" v-model="queryParam.orgIdCompany">-->
							<!--                <a-radio-button value="">-->
							<!--                  全部-->
							<!--                </a-radio-button>-->
							<!--                <a-radio-button :value="id" v-for="{id, name} in orgs">-->
							<!--                  {{ name }}-->
							<!--                </a-radio-button>-->
							<!--              </a-radio-group>-->

						</a-form-item>
					</a-col>
					<a-col :md="8" :sm="24">
						<a-form-item label="物料编号">
							<a-input v-model="queryParam.jzMaterialCode" placeholder="请输入物料编号" />
						</a-form-item>
					</a-col>
					<a-col :md="8" :sm="24">
						<a-form-item label="领用方">
							<a-select placeholder="全部" v-model="queryParam.classGroupId">
								<a-select-option :values="item.classGroupId" v-for="item in teamList" :key="item.classGroupId">
									{{ item.name }}
								</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<a-col :md="!advanced && 8 || 24" :sm="24">
						<span class="table-page-search-submitButtons"
							:style="advanced && { float: 'right', overflow: 'hidden' } || {}">
							<a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
							<a-button style="margin-left: 8px"
								@click="() => { queryParam.orderNumber = null; queryParam.orgId = null; queryParam.jzMaterialCode = null; queryParam.classGroupId = null;$refs.table.refresh(true) }">重置</a-button>
						</span>
					</a-col>

				</a-row>
			</a-form>
		</div>

		<s-table ref="table" size="default" :columns="columns" :data="loadData" :alert="true"
			:rowKey="(record) => record.code" :rowSelection="null">
			<span slot="action" slot-scope="text, record">
				<a @click="$refs.outStoreDetailModal.show(record, '出库详情', '', { materialType })">出库详情</a>
				<a-divider type="vertical" />
				<a
					@click="$refs.outStoreRecordModal.show(record, '出库明细', 'outOrder', { 'orderType': $businessEnum.ORDER_TYPE_ENUM.outOrder.id })">出库明细</a>
				<a-divider type="vertical" />
				<a @click="$refs.backStoreDetailModal.show(record)">退库详情</a>
				<a-divider type="vertical" />
				<a @click="$refs.backStoreRecordDetailModal.show(record)">退库入库单明细</a>
			</span>
		</s-table>

		<out-store-detail-modal ref="outStoreDetailModal" />
		<out-store-record-modal ref="outStoreRecordModal" />
		<back-store-record-detail-modal ref="backStoreRecordDetailModal" />
		<back-store-detail-modal ref="backStoreDetailModal" />

	</a-card>
</template>

<script>
import { STable } from '@/components'
import { page } from '@/api/modular/main/emsorder/emsOrderManage'
import FCOrgRadioGroup from '@/components/FcOrgRadioGroup/FCOrgRadioGroup'
import OutStoreDetailModal from './outStoreDetailModal'
import OutStoreRecordModal from './outStoreRecordModal'
import BackStoreRecordDetailModal from './backStoreRecordDetailModal.vue'
import BackStoreDetailModal from './backStoreDetailModal.vue'

import { page as teamPage } from '@/api/modular/main/classGroup/classGroup'

export default {

	components: {
		STable,
		FCOrgRadioGroup,
		OutStoreDetailModal,
		OutStoreRecordModal,
		BackStoreRecordDetailModal,
		BackStoreDetailModal
	},
	created() {
		this.getTeamList();
	},
	data() {
		return {
			advanced: false, // 高级搜索 展开/关闭
			columns: [
				{
					title: '序号', width: '80px',
					customRender: (text, record, index) => `${index + 1}`
				},
				{
					title: '生产单号',
					dataIndex: 'orderNumber'
				},
				{
					title: '开始时间',
					dataIndex: 'createTime'
				},
				{
					title: '结束时间',
					dataIndex: ''
				},
				{
					title: '操作',
					dataIndex: '',
					width: '360px',
					scopedSlots: { customRender: 'action' }
				}
			],
			queryParam: {},  // 查询参数
			// 加载数据方法 必须为 Promise 对象
			loadData: parameter => {
				this.queryParam.orderType = this.$businessEnum.ORDER_TYPE_ENUM.produceOrder.id
				// 查询所有包含包材的生产单即可
				this.queryParam.materialType = this.$businessEnum.MATERIAL_TYPE_ENUM.packing.id
				return page(Object.assign(parameter, this.queryParam)).then((res) => {
					return res.data
				})
			},
			scheduleProductionVisible: false,
			selectedRowKeys: [],
			selectedRows: [],
			defaultExpandedKeys: [],
			replaceFields: {
				key: 'id',
			},
			urlParam: {},
			columnsType: '',
			suppliers: [],
			materialType: this.$businessEnum.MATERIAL_TYPE_ENUM.packing.id,
			teamList: [],
		}
	},
	methods: {
		toggleAdvanced() {
			this.advanced = !this.advanced
		},
		handleOk() {
			this.$refs.table.refresh()
			this.$refs.table.clearSelected()
		},
		//获取领用方
		getTeamList() {
			teamPage({
				pageSize: -1,
				status: 0
			}).then(res => {
				this.teamList = res.data.rows;
			})
		},
		onSelectChange(selectedRowKeys, selectedRows) {
			this.selectedRowKeys = selectedRowKeys
			this.selectedRows = selectedRows
		},
		//总经理，以及四个仓库的管理员    返回true
		isFour() {
			return this.hasRole(this.$util.ROLE_ENUM.SQCG.id)   //采购
		},
	}
}
</script>

<style lang="less">
.table-operator {
	margin-bottom: 18px;
}

button {
	margin-right: 8px;
}
</style>
